class TempExaminationResoult < ActiveRecord::Base
  has_many :param_resoults
  belongs_to :order_examination
  belongs_to :user
  after_update :save_params

  def param_resoult_attributes=(param_resoult_attributes)
    param_resoult_attributes.each do |atributes|
      if atributes[:id].blank?
        param_resoults.build(atributes)
      else
        param = param_resoults.detect { |t| t.id == atributes[:id].to_i }
        param.attributes = atributes
      end
    end
  end

  def save_params
    param_resoults.each do |t|
      t.save(false)
    end
  end
end
